
# include "dfxAudioPlugin.h"
# include "dfxLog.h"

namespace DFX
{
    AudioPlugin::AudioPlugin(const String &dllFile)
        : Plugin("Audio"), 
        mDllFile(dllFile),
        mAudioDeviceCreate(NULL)
    {
    }

    AudioPlugin::~AudioPlugin()
    {
        Unload();
    }
    
    DFXRESULT AudioPlugin::AudioDeviceCreate(AudioDevice **ad)
    {
        if (mAudioDeviceCreate)
            return mAudioDeviceCreate(ad);

        return DFX_CREATEFAILED;
    }

    DFXRESULT AudioPlugin::Load()
    {
        LoadDLL(mDllFile, (void*)&mHandle);

        if (mHandle)
        {
            mAudioDeviceCreate  = (AUDIODEVICECREATE)GetFunction("AudioDeviceCreate", (void*)&mHandle);
            return DFX_SUCCESS;
        }

        return DFX_LOADFAILED;
    }

    DFXRESULT AudioPlugin::Unload()
    {
        if (mHandle)
            UnloadDLL((void*)&mHandle);

        return DFX_SUCCESS;
    }
}